<!DOCTYPE HTML>
<html>
<head th:replace="mgr/base/head :: head('用户自定义页面管理')"></head>
<body>
		<nav th:replace="mgr/base/nav :: active('tpl-user')"></nav>
		<div id="page-wrapper" style="padding: 10px">
			<div class="container-fluid">
				<div class="row" style="margin-bottom: 10px">
					<div class="col-md-12">
						<a class="btn btn-default" th:href="@{/mgr/page/user/new}"
							role="button">创建新页面</a>
					</div>
				</div>
				<div class="row">
					<div class="col-md-12">
						<div class="alert alert-danger" th:unless="${error == null}"
							th:text="${messages.getMessage(error)}"></div>
						<form style="display: none" th:action="@{/mgr/page/user/index}"
							id="pageForm">
							<input type="hidden" th:value="${page.currentPage}"
								name="currentPage" />
						</form>
						<div class="alert alert-info"
							th:if="${#lists.isEmpty(page.datas)}">当前没有任何自定义页面</div>
						<div th:unless="${#lists.isEmpty(page.datas)}">
							<div class="table-responsive">
								<table class="table">
									<thead>
										<tr>
											<th>页面ID</th>
											<th>页面名</th>
											<th>别名</th>
											<th>描述</th>
											<th>空间</th>
											<th>创建日期</th>
											<th>操作</th>
										</tr>
									</thead>
									<tbody>
										<tr th:each="page : ${page.datas}">
											<td th:text="${page.id}"></td>
											<td><a href="###" th:title="${page.name}"
												data-toggle="tooltip"
												th:text="${#strings.length(page.name) > 10  ? #strings.substring(page.name,0,10)+'...' : page.name}"></a></td>
											<td><a href="###" th:if="${page.alias != null}" th:title="${page.alias}"
												data-toggle="tooltip"
												th:text="${#strings.length(page.alias) > 10  ? #strings.substring(page.alias,0,10)+'...' : page.alias}"></a></td>
											<td><a href="###" th:title="${page.description}"
												data-toggle="tooltip"
												th:text="${#strings.length(page.description) > 10  ? #strings.substring(page.description,0,10)+'...' : page.description}"></a></td>
											<td>
												<span th:if="${page.space == null}" th:text="无"></span>
												<a href="###" data-toggle="tooltip" th:title="${page.space.name}" th:if="${page.space != null}" th:text="${#strings.length(page.space.name) > 10  ? #strings.substring(page.space.name,0,10)+'...' : page.space.name}"></a>
											</td>
											<td
												th:text="${#dates.format(page.createDate, 'yyyy-MM-dd HH:mm')}"></td>
											<td><a href="###" style="margin-right: 10px"
												data-action="remove" th:data-id="${page.id}"><span
													class="glyphicon glyphicon-remove" aria-hidden="true"></span></a>
												<a th:href="@{/mgr/page/user/update?id=}+${page.id}" style="margin-right: 10px"><span
													class="glyphicon glyphicon-edit" aria-hidden="true"></span></a>
												<a href="###" data-action="link" th:data-link="${urls.getUrl(page)}" title="获取页面链接"><span class="glyphicon glyphicon-link" aria-hidden="true"></span></a>
											</td>
										</tr>
									</tbody>
								</table>
							</div>
						</div>
						<div th:if="${page.totalPage > 1}">
							<ul class="pagination">
								<li
									th:each="i : ${#numbers.sequence(page.listbegin, page.listend-1)}">
									<a th:text="${i}" th:data-page="${i}" href="###"></a>
								</li>
							</ul>
						</div>
				</div>
			</div>
		</div>
	</div>
	<div th:replace="base/foot_source"></div>
	<script type="text/javascript">
		$(document).ready(function(){
			$('[data-toggle="tooltip"]').tooltip();
			$("[data-page]").click(function(){
				var page = $(this).attr("data-page");
				$("#pageForm").find("input[name='currentPage']").val(page);
				$("#pageForm").submit();
			});
			$("a[data-action]").click(function(){
				var me = $(this);
				var action = me.attr("data-action");
				switch(action){
				case "remove":
					bootbox.confirm("确定要删除吗？",function(result){
						if(result){
							$.ajax({
		    					type : "post",
		    					url : basePath+"/mgr/page/user/delete",
		    					data : {"id":me.attr("data-id")},
		    					success : function(data){
		    						if(data.success){
		    							window.location.reload()
		    						}else{
			    						bootbox.alert(data.message);
		    						}
		    					},
		    					complete:function(){
		    					}
		    				});
						}
					})
					break;
				case "link":
					var link = me.attr('data-link');
					bootbox.dialog({
						title : '页面访问链接',
			            message: '<a href="'+link+'" target="_blank">'+link+'</a>',
			            buttons: {
			                success: {
			                    label: "确定",
			                    className: "btn-success"
			                }
			            }
					});
					break;
				}
			})
		});
	</script>
</body>
</html>